|
Data, context and interaction (DCI) is a paradigm used in computer software to program systems of communicating objects. Its goals are: * To improve the readability of object-oriented code by giving system behavior first-class status; * To cleanly separate code for rapidly changing system behavior (what a system ''does'') versus slowly changing domain knowledge (what a system ''is''), instead of combining both in one class interface; * To help software developers reason about system-level state and behavior instead of only object state and behavior; * To support an object style of thinking that is close to peoples' mental models, rather than the class style of thinking that overshadowed object thinking early in the history of object-oriented programming languages. The paradigm separates the domain model (data) from use cases (context) and Roles that objects play (interaction). DCI is complementary to model–view–controller (MVC). MVC as a pattern language is still used to separate the data and its processing from presentation. DCI was invented by Trygve Reenskaug, also the inventor of MVC. The current formulation of DCI is mostly the work of Reenskaug and James O. Coplien. ==Description== ;Data :The data are "what the system ''is''." The ''data'' part of the DCI architecture is its (relatively) static data model with relations. The data design is usually coded up as conventional classes that represent the basic domain structure of the system. These classes are barely smart data, and they explicitly lack the functionality that is peculiar to support of any particular use case. These classes commonly encapsulate the physical storage of the data. These data implement an information structure that comes from the mental model of end users, domain experts, programmers, and other ''people'' in the system. They may correspond closely to the model objects of MVC. :An example of a data object could be a bank account. Its interface would have basic operations for increasing and decreasing the balance and for inquiring about the current balance. The interface would likely not offer operations that involve transactions, or which in any way involve other objects or any user interaction. So, for example, while a bank account may offer a primitive for increasing the balance, it would have no method called deposit . Such operations belong instead in the interaction part of DCI.:Data objects are instances of classes that might come from domain-driven design, and such classes might use subtyping relationships to organize domain data. Though it reduces to classes in the end, DCI reflects a computational model dominated by object thinking rather than class thinking. Therefore, when thinking "data" in DCI, it means thinking more about the instances at run time than about the classes from which they were instantiated. ;Context :The context is the class (or its instance) whose code includes the Roles for a given algorithm, scenario, or use case, as well as the code to map these Roles into objects at run time and to enact the use case. Each Role is bound to exactly one object during any given use case enactment; however, a single object may simultaneously play several Roles. A context is instantiated at the beginning of the enactment of an algorithm, scenario, or use case. In summary, a context comprises use cases and algorithms in which data objects are used through specific Roles. :Each context represents one or more use cases. A context object is instantiated for each enactment of a use case for which it is responsible. Its main job is to identify the objects that will participate in the use case and to assign them to play the Roles which carry out the use case through their responsibilities. A Role may comprise methods, and each method is some small part of the logic of an algorithm implementing a use case. Role methods run in the context of an object that is selected by the context to play that Role for the current use case enactment. The Role-to-object bindings that take place in a context can be contrasted with the polymorphism of vernacular object-oriented programming. The overall business functionality is the sum of complex, dynamic networks of methods decentralized in multiple contexts and their Roles. :Each context is a scope that includes identifiers that correspond to its Roles. Any Role executing within that context can refer to the other Roles in that context through these identifiers. These identifiers have come to be called ''methodless Roles''. At use case enactment time, each and every one of these identifiers becomes bound to an object playing the corresponding Role for this context. :An example of a context could be a wire transfer between two accounts, where data models (the banking accounts) are used through Roles named SourceAccount and DestinationAccount. ;Interaction :The interaction is "what the system ''does''." The interaction is implemented as Roles which are played by objects at run time. These objects combine the state and methods of a data (domain) object with methods (but no state, as Roles are stateless) from one or more Roles. In good DCI style, a Role addresses another object only in terms of its (methodless) Role. There is a special Role called self which binds to the object playing the current Role. Code within a Role method may invoke a method on self and thereby invoke a method of the data part of the current object. One curious aspect of DCI is that these bindings are guaranteed to be in place only at run time (using a variety of approaches and conventions; C++ templates can be used to guarantee that the bindings will succeed). This means that interactions, the Role methods, are ''generic''. In fact, some DCI implementations use generics or templates for Roles.:A Role is a stateless programming construct that corresponds to the end user's mental model of some entity in the system. A Role represents a collection of responsibilities. Whereas vernacular object-oriented programming speaks of objects or classes as the loci of responsibilities, DCI ascribes them to Roles. An object participating in a use case has responsibilities: those that it takes on as a result of playing a particular Role. Most modern programming languages have a way to express Roles, and to express the injection of Role methods into objects, and implementation techniques vary depending the language. The injection can be fully dynamic at run-time in languages like Ruby and Python; it is more static in languages like Smalltalk-Squeak, Scala and C++. The Qi4j programming environment offers a way to express Role method injection into Java objects.〔(Qi4j framework )〕 Java 8 (default method ) on interfaces can be used to implement Roles in a typesafe way. :In the above money transfer use case, for example, the Role methods in the SourceAccount and DestinationAccount enact the actual transfer. 抄文引用元・出典: フリー百科事典『 ウィキペディア(Wikipedia)』 ■ウィキペディアで「Data, context and interaction」の詳細全文を読む スポンサード リンク
|